package cn.jtool.dig.common.model;

import cn.jtool.dig.common.netty.supports.ByteBuffer;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PacketHeader {

    private Integer command;

    private Integer digId;

    private Long channelId;

    private Integer sn;

    public PacketHeader(byte[] bytes) {
        ByteBuffer buffer = new ByteBuffer(bytes);
        this.command = buffer.readByte();
//        this.digId = buffer.readByte();
        this.channelId = buffer.readDWord();
        this.sn = buffer.readWord();
    }

    public byte[] toBytes(){
        ByteBuffer buffer = new ByteBuffer();
        buffer.writeByte(this.command);
//        buffer.writeByte(this.digId);
        buffer.writeDWord(this.channelId);
        buffer.writeWord(this.sn);
        return buffer.readAll();
    }
}
